home *** CD-ROM | disk | FTP | other *** search
/ Wayzata's Best of Shareware PC/Windows 2 / Wayzata's Best of Shareware 2.0 (Windows) (Wayzata Technology)(7112)(1994).bin / pc / dos / programg / pbwiz15 / pbwiz.doc < prev    next >
Text File  |  1992-10-04  |  68KB  |  1,788 lines

  1.                 The PowerBASIC Wizard's Library
  2.                 =-----------------------------=
  3.                           Version 1.5
  4.  
  5.      PBWIZ  Copyright (c) 1991-1992  Thomas G. Hanlin III
  6.  
  7.  
  8.  
  9. This is PBWiz, a library of assembly language and BASIC
  10. routines for use with PowerBASIC version 2.x.  The PBWiz
  11. collection is copyrighted, but may be distributed as long as
  12. the following conditions are obeyed:
  13.  
  14.    All PBWiz files must be distributed together in unmodified
  15.    form.  No files may be removed or added.
  16.  
  17. You use this library at your own risk.  It has been tested by
  18. me on my own computer, but I will not assume any responsibility
  19. for any problems which PBWiz may cause you.  If you do
  20. encounter a problem, please let me know about it, and I will do
  21. my best to verify and repair the error.
  22.  
  23. It is expected that if you find PBWiz useful, you will register
  24. your copy. You may not use PBWiz routines in programs intended
  25. for distribution unless you have registered.  Registration
  26. entitles you to receive the latest version of PBWiz, complete
  27. with full source code in assembly language and BASIC.  The
  28. assembly code is designed for the MASM 6.0 assembler and may
  29. require modifications for use with other assemblers.  See
  30. REGISTER.TXT for details on registration.
  31.  
  32. Warning: Unregistered use of PBWiz for more than 30 days may
  33. cause the author to sing Gregorian chants under your window.
  34. Don't let this happen to you!
  35.  
  36.                        Table of Contents                 page 2
  37.  
  38.  
  39.  
  40.  Synopsis and Legal Info .................................... 1
  41.  
  42.  Table of Contents .......................................... 2
  43.  
  44.  Overview ................................................... 3
  45.  
  46.  ANSI emulation ............................................. 4
  47.  
  48.  Archives ................................................... 5
  49.  
  50.  Dates and Times ............................................ 7
  51.  
  52.  Disk Directories ........................................... 8
  53.  
  54.  Equipment Info ............................................ 10
  55.  
  56.  Extended Math ............................................. 14
  57.  
  58.  Graphics .................................................. 17
  59.  
  60.  Keyboard .................................................. 20
  61.  
  62.  Memory (EMS) .............................................. 24
  63.  
  64.  Memory (XMS) .............................................. 27
  65.  
  66.  Mouse Support ............................................. 29
  67.  
  68.  Strings ................................................... 32
  69.  
  70.  Text-mode Video ........................................... 35
  71.  
  72.  Credits ................................................... 40
  73.  
  74.                            Overview                      page 3
  75.  
  76.  
  77.  
  78. Any program that uses any of the PBWiz routines must DECLARE
  79. them appropriately.  To make this easy, I've created a single
  80. file which contains all of the necessary declarations.  Put
  81. the following line at the top of your program to use it:
  82.  
  83.    $INCLUDE "pbwiz.inc"
  84.  
  85. The DECLARE statements contained in this file tell PowerBASIC
  86. how to behave when it runs into any PBWiz routines.  They
  87. don't actually load the routines.  To do that, you must $LINK
  88. the appropriate units.  The names of the units to $LINK are
  89. specified in each chapter of this manual.
  90.  
  91. Each chapter covers a specific unit or pair of units.  If the
  92. code is written in assembly language, the unit name ends in A.
  93. If the code is written in PowerBASIC, the unit name ends in B.
  94. So, for instance, the VIDEO units are called VIDEOA.OBJ and
  95. VIDEOB.PBU.  If the code for a chapter is written entirely in
  96. one language, I don't bother with -A or -B suffix.
  97.  
  98.                         ANSI Emulation                   page 4
  99.  
  100.  
  101.  
  102. The ANSI emulator allows you to display text with ANSI codes
  103. without any need for ANSI.SYS or other ANSI drivers.  All you
  104. have to do is bring the ANSI emulator into your program:
  105.  
  106.    $LINK "ansiprin.pbu"
  107.  
  108. Replace any PRINT statements with a call to the ANSI emulator:
  109.  
  110.    PRINT St$;
  111.  
  112. turns into
  113.  
  114.    CALL AnsiPrint (St$)
  115.  
  116. Note that this does not include a carriage return and linefeed.
  117. If you want one, you'll have to add it explicitly:
  118.  
  119.    St$ = St$ + CHR$(13) + CHR$(10)
  120.    CALL AnsiPrint (St$)
  121.  
  122. Other ASCII codes are supported as well, including CHR$(7)
  123. [bell], CHR$(8) [backspace], and CHR$(12) [formfeed].
  124.  
  125. For a list of ANSI display codes, see your DOS manual or check
  126. with your local BBS.
  127.  
  128.                            Archives                      page 5
  129.  
  130.  
  131.  
  132. When I started in the microcomputer industry, there was a
  133. small variety of file archivers, all (more or less)
  134. compatible.  They did not provide compression, which was
  135. relegated to another large selection of more-or-less
  136. compatible utilities.  Then came SEA's ARC.  It was very slow,
  137. but it did compression as well as archiving, and included CRC
  138. checks so you could know whether the files were intact.  It
  139. swept the BBS scene in short order, becoming the new
  140. standard.  A few other archivers competed on about a level
  141. footing, providing only minor variances on the ARC theme. Then
  142. SEA decided to sue one of its more successful competitors,
  143. Phil Katz (PKARC).  The end result was the ZIP standard... but
  144. in the chaos resulting from the breaking of the ARC standard,
  145. many other archivers came into being: ARJ, LZH, PAK, ZOO, and
  146. so forth.
  147.  
  148. PBWiz helps resolve the confusion by providing a single set of
  149. routines which allow you to view the contents of archives in
  150. any of the above-mentioned formats: ARC, ARJ, LZH, PAK, ZIP, or
  151. ZOO.  It also handles self-extracting EXE files of the form
  152. produced by LHARC.  Only archive directories are provided at
  153. this time.  Other formats will also be added as they arise.  If
  154. you have details on the format of an archive that you'd like me
  155. to add to PBWiz, please send them my way.
  156.  
  157. This unit requires the STRING unit (discussed later) as well.
  158. To use it in your program, you need to include both units:
  159.  
  160.    $LINK "stringa.obj"
  161.    $LINK "stringb.pbu"
  162.    $LINK "archives.pbu"
  163.  
  164. Viewing archive directories is handled in roughly the same
  165. fashion as you might view a DOS file directory.  This makes it
  166. possible to treat an archive and a subdirectory in a similar
  167. manner.
  168.  
  169. When you're looking for the first file in an archive, use the
  170. FindFirstA function.  You must specify the archive name and a
  171. file name.  The archive name may include a drive and path
  172. specification, and does not need to have the archive
  173. extension.  If you leave off the extension, FindFirstA will use
  174. the first archive it comes across that matches the rest of the
  175. specification. Note that the archive specification may not
  176. contain wildcards.  In contrast, the search file name may not
  177. contain drive or path specs, but may contain wildcards.
  178.  
  179.    CALL FindFirstA (Archive$, Filename$, ErrCode%)
  180.  
  181.                            Archives                      page 6
  182.  
  183.  
  184.  
  185. If there are no files to be found, or if the archive
  186. specification was bad, an error code will be returned.  If
  187. there was no error, there may well be more files to be found.
  188. You can find each of them with FindNextA:
  189.  
  190.    CALL FindNextA (ErrCode%)
  191.  
  192. Of course, just finding a matching file doesn't do you much
  193. good unless you can retrieve information about it.  You can use
  194. any of the following routines to provide information about a
  195. matched file:
  196.  
  197.    Nam$ = GetNameA$
  198.    Dat$ = GetDateA$
  199.    Tim$ = GetTimeA$
  200.    CRC$ = GetCRCA$
  201.    StorageMethod$ = GetStoreA$
  202.  
  203.    CALL GetSizeA (OriginalSize&, CurrentSize&)
  204.  
  205. When you're done viewing an archive, be sure to close it:
  206.  
  207.    CALL CloseA
  208.  
  209. Let's try an example.  Given that you've already written the
  210. $LINK line as specified on the previous page, you could see
  211. all of the files in an archive using a program like this:
  212.  
  213.    CALL FindFirstA (Archive$, "*.*", ErrCode%)
  214.    DO UNTIL ErrCode%
  215.       PRINT GetNameA$
  216.       CALL FindNextA (ErrCode%)
  217.    LOOP
  218.    CALL FCloseA
  219.  
  220. This program fragment also assumes that you have set Archive$
  221. to the name of an archive.  It might be convenient to set it to
  222. the command line for testing purposes:
  223.  
  224.    Archive$ = UCASE$(LTRIM$(RTRIM$(COMMAND$)))
  225.  
  226.                         Dates and Times                  page 7
  227.  
  228.  
  229.  
  230. This unit allows you to validate and compare dates.  It also
  231. provides the day of the week, given the date.  Dates may not be
  232. before the year 1900.  Date strings may be in the form
  233. "01/01/91" or "01-01-1991" (the delimiter is not significant
  234. and years may be two or four digits; two-digit years will be
  235. assumed to be in the 20th century).
  236.  
  237. To use the routines in this unit, include the following line
  238. at the top of your program:
  239.  
  240.    $LINK "timedate.pbu"
  241.  
  242. Let's start off with date validation.  It's often important to
  243. know if a date entered into your program is a valid date.
  244.  
  245.    IF GoodDate%(DateSt$) THEN PRINT "The date is valid."
  246.  
  247. It can also be helpful to know on which day of the week a given
  248. date falls.
  249.  
  250.    Day$ = WeekDay$(DateSt$)
  251.  
  252. There are many useful things you can accomplish by turning a
  253. date into a number which represents that date (or vice versa).
  254. This allows you to compare two dates, which is important if you
  255. want to sort by date; find out what the date will be in a given
  256. number of days, or what it was some number of days ago; find
  257. the number of days between two dates; display a calendar; and
  258. so forth.  This is easy to do with PBWiz:
  259.  
  260.    DateNr& = Date2Num&(DateSt$)
  261.  
  262.    DateSt$ = Num2Date$(DateNr&)
  263.  
  264. The DateNr& represents the number of days since January 1,
  265. 1900.  This is less than 65,535 for dates that go up to around
  266. the year 2070 or so, so you may wish to store the dates in
  267. compressed two-byte form if your required range of dates is not
  268. that large:
  269.  
  270.    CrunchDate% = CVI(LEFT$(MKL$(DateNr&), 2))
  271.  
  272. This can be reversed simply:
  273.  
  274.    DateNr& = CVL(MKI$(CrunchDate%) + STRING$(2, 0))
  275.  
  276. Note that dates crunched this way are only useful for storage
  277. purposes, since the numbers greater than 32,767 are stored as
  278. negative numbers due to the signed integer format BASIC uses.
  279. You must uncompress them before doing any comparisons or date
  280. calculations.  Still, for a savings of 50%, it may be worth the
  281. hassle to convert back and forth.
  282.  
  283.                        Disk Directories                  page 8
  284.  
  285.  
  286.  
  287. This unit lets you read disk directories and retrieve the same
  288. information the DIR command shows, plus the file attribute.  A
  289. string buffer is used to allow recursive directory searching.
  290.  
  291. To use it in your program, include the DirMgr unit:
  292.  
  293.    $LINK "dirmgr.obj"
  294.  
  295. When you're looking for the first file in a directory, use the
  296. FindFirstF function.  You must provide a search filespec, which
  297. may contain a drive and path specification and use wildcards.
  298. You must also provide a search attribute, which may be any
  299. combination of the following added together:
  300.  
  301.    Normal          0      (nothing special)
  302.    Read Only       1      file can be read, but not written to
  303.    Hidden          2      file is "invisible"
  304.    System          4      special DOS system file
  305.    Subdirectory   16      subdirectory
  306.    Archive        32      (used by some backup utilities)
  307.  
  308. Note that you will always get all files that match any of your
  309. search specs.  For example, if your search attribute was 18,
  310. you'd get normal files, hidden files, normal subdirectories and
  311. hidden subdirectories.  If you want to be more specific, you
  312. will have to test the file attribute of the resulting file.
  313.  
  314. You must provide a string buffer for the directory search
  315. routine.  This buffer must be 64 characters long and should be
  316. initialized before each call to FindFirstF.  By using different
  317. buffer strings, you can search more than one directory at a
  318. time, or perform recursive searches through directories.
  319.  
  320.    Buffer$ = SPACE$(64)
  321.    CALL FindFirstF (Buffer$, Filename$, ErrCode%)
  322.  
  323. If there are no files to be found, or if the file specification
  324. was bad, an error code will be returned.  If there was no
  325. error, there may well be more files to be found.  You can find
  326. each of them with FindNextF:
  327.  
  328.    CALL FindNextF (Buffer$, ErrCode%)
  329.  
  330. Of course, just finding a matching file doesn't do you much
  331. good unless you can retrieve information about it.  You can use
  332. any of the following routines to provide information about a
  333. matched file:
  334.  
  335.    FilAttr% = GetAttrF%(Buffer$)       ' file attribute
  336.    FilName$ = GetNameF$(Buffer$)       ' file name
  337.    FilDate$ = GetDateF$(Buffer$)       ' file date
  338.    FilSize& = GetSizeF&(Buffer$)       ' file size
  339.    FilTime$ = GetTimeF$(Buffer$)       ' file time
  340.  
  341.                        Disk Directories                  page 9
  342.  
  343.  
  344.  
  345. The file attribute can be most readily decoded with a series of
  346. ANDs.  For example, to test for a subdirectory, you'd use:
  347.  
  348.    IF FilAttr% AND 16 THEN PRINT "subdirectory"
  349.  
  350. Let's put all these routines together and see what it takes to
  351. make a quick'n'dirty DIR-style utility.
  352.  
  353.    $INCLUDE "pbwiz.inc"
  354.    $LINK "dirmgr.obj"
  355.    SearchName$ = COMMAND$  ' get search spec from command line
  356.    Buffer$ = SPACE$(64)    ' set up buffer
  357.    CALL FindFirstF(Buffer$, SearchName$, SearchAttr%, ErrCode%)
  358.    DO UNTIL ErrCode%
  359.       PRINT GetNameF$(Buffer$), GetSizeF&(Buffer$),
  360.       PRINT GetDateF$(Buffer$), GetTimeF$(Buffer$),
  361.       FilAttr% = GetAttrF%(Buffer$)
  362.       IF FilAttr% AND 1 THEN PRINT "Read Only  ";
  363.       IF FilAttr% AND 2 THEN PRINT "Hidden  ";
  364.       IF FilAttr% AND 4 THEN PRINT "System  ";
  365.       IF FilAttr% AND 16 THEN PRINT "Subdirectory  ";
  366.       IF FilAttr% AND 32 THEN PRINT "Backup  ";
  367.       PRINT
  368.       CALL FindNextA (ErrCode%)
  369.    LOOP
  370.  
  371. Doesn't take much, does it?  Now you can add disk directory
  372. handling to your program with a bare minimum of effort!
  373.  
  374.                         Equipment Info                  page 10
  375.  
  376.  
  377.  
  378. The equipment unit gives you information about the computing
  379. environment. This includes both installed software and
  380. hardware.  You can use the equipment information routines by
  381. including this line in your program:
  382.  
  383.    $LINK "equipmen.obj"
  384.  
  385. The first function allows you to determine if an "enhanced"
  386. keyboard (101-key) is installed.  It may not be able to figure
  387. out what the keyboard is on some older not-quite-clone PCs, in
  388. which case it will take the safe way out and report that there
  389. is no enhanced keyboard.  This function returns -1 if there is
  390. an enhanced keyboard present, 0 if not.
  391.  
  392.    Enhanced% = KbdType%
  393.  
  394. Want to know the type of processor (CPU) being used?  Can do!
  395.  
  396.    CPU% = Processor%
  397.  
  398. The results will be reported as a number which can be decoded
  399. as follows:
  400.  
  401.    0    NEC V20
  402.    1    8088 or 8086
  403.    2    80186
  404.    3    80286
  405.    4    80386
  406.    5    80486
  407.  
  408. Maybe you'd like to check for a CD-ROM drive:
  409.  
  410.    Drives% = CDROM%
  411.  
  412. This tells you how many logical drives exist, if there is a
  413. CD-ROM available. If not, it will return 0.  Note that the
  414. CD-ROM installation check conflicts with the GRAPHICS.COM
  415. installation check for DOS 4.0, due to some screw-up at IBM or
  416. Microsoft.  I'm not yet sure whether DOS 5.0 is similarly
  417. afflicted.
  418.  
  419. The number of floppy drives installed is retrieved like this:
  420.  
  421.    Drives% = Floppies%
  422.  
  423.                         Equipment Info                  page 11
  424.  
  425.  
  426.  
  427. There may be up to four floppy drives in a system; however, the
  428. AT CMOS data area only directly supports two. This makes it
  429. easy to find out what kind of drives the first two are, but not
  430. the second two.  Oh well, guess we'll have to settle for what
  431. we can get, right?
  432.  
  433.    CALL FloppyType (Drive1, Drive2)
  434.  
  435. The results from FloppyType are returned as follows:
  436.  
  437.    0    no drive
  438.    1    5 1/4"    360K
  439.    2    5 1/4"    1.2M
  440.    3    3 1/2"    720K
  441.    4    3 1/2"    1.44M
  442.  
  443. Result codes of 5-7 are available, but not yet defined.  One
  444. might guess that the 2.88M drive supported by DOS 5.0 will be
  445. drive type 5.  Has anybody seen one of those puppies yet?
  446.  
  447. New memory types sure have burgeoned over the years...
  448. expanded, extended, and now XMS.  There are routines to check
  449. all of these:
  450.  
  451.    BaseExt& = AllExtMem&     ' extended memory installed
  452.    NowExt& = GetExtM&        ' BIOS extended memory available
  453.  
  454.    CALL GetEMSm (TotalPages%, FreePages%)    ' expanded memory
  455.  
  456.    CALL GetXMSm (LargestFree&, TotalFree&)   ' XMS memory
  457.  
  458. When you're dealing with extended memory, whether it be
  459. BIOS-type or using the XMS standard, the results are returned
  460. in kilobytes.  Multiply 'em by 1024 to convert to bytes.  When
  461. you're dealing with expanded memory (EMS), the results are in
  462. pages of 16,384 bytes.
  463.  
  464. I might note, by the way, that Microsoft seems to have
  465. intentionally crippled the XMS standard.  It can only support a
  466. maximum of 64 megabytes.  This may seem like a lot now, but I
  467. can remember when my first PC (a Compaq portable) was the awe
  468. of the neighborhood with 384K RAM!  A few years down the road,
  469. the artificial limitations of XMS are going to be a nuisance.
  470.  
  471. A few more routines to get the versions of the EMS and XMS
  472. drivers, if any:
  473.  
  474.    CALL GetEMSv (MajorV%, MinorV%)
  475.    CALL GetXMSv (MajorV%, MinorV%)
  476.  
  477. These return the major and minor version numbers as two
  478. separate integers. For example, EMS 4.0 would return major
  479. version 4, minor version 0.
  480.  
  481.                         Equipment Info                  page 12
  482.  
  483.  
  484.  
  485. It's nice to know a little about the operating environment.
  486. With the below routines, you can find out what the DOS version
  487. is; what version of 4DOS, if any, is in use; and whether
  488. Microsoft Windows is running.
  489.  
  490.    CALL GetDOSv (MajorV%, MinorV%)
  491.    CALL Get4DOSv (MajorV%, MinorV%)
  492.    CALL WinCheck (MajorV%, MinorV%)
  493.  
  494. These return results as major and minor version numbers, as
  495. discussed on the previous page.  The Get4DOSv and WinCheck
  496. routines return zeroes if 4DOS and Windows, respectively, are
  497. not available.
  498.  
  499. There are a couple of curious features of GetDOSv to keep in
  500. mind.  If the version is 10 or higher, you're running in OS/2
  501. compatibility mode.  DOS version 10 is actually OS/2 1.0,
  502. version 20 is OS/2 2.0, and so on. Secondly, if you're using
  503. DOS 5.0, the version reported may not be 5.0-- DOS 5.0 can be
  504. told to reply with a lower version number to allow some older
  505. software (which checks for a specific DOS version) to run
  506. properly.
  507.  
  508. One final routine that should be of some value is the one that
  509. allows you to find out what kind of display is available.  It
  510. tells you the specific adapter and whether the display is color
  511. or monochrome.  There is one case in which it can be confused,
  512. however-- if the adapter is CGA, the display is assumed to be
  513. color, since there is no way for the computer to know any
  514. differently.  So, although this routine provides a good idea of
  515. what is available, it would be a good idea to provide an option
  516. to tell the program that a monochrome display is attached.
  517. Microsoft normally uses "/B" for this purpose, so that might be
  518. a good standard to stick with.
  519.  
  520.    CALL GetDisplay (Adapter%, Mono%)
  521.    IF Mono% THEN
  522.       PRINT "Monochrome monitor"
  523.    ELSE
  524.       PRINT "Color monitor"
  525.    END IF
  526.    SELECT CASE Adapter%
  527.       CASE 1: PRINT "MDA"
  528.       CASE 2: PRINT "Hercules"
  529.       CASE 3: PRINT "CGA"
  530.       CASE 4: PRINT "EGA"
  531.       CASE 5: PRINT "MCGA"
  532.       CASE 6: PRINT "VGA"
  533.    END SELECT
  534.  
  535.                         Equipment Info                  page 13
  536.  
  537.  
  538.  
  539. Aside from some of the oldest semi-clones, it's possible to
  540. find out what sort of machine you're using by looking at a
  541. specific data byte.  You can access this as follows:
  542.  
  543.    Machine% = PCType%
  544.  
  545. The result will need decoding.  Here are some known values:
  546.  
  547.    255   PC or XT
  548.    254   XT
  549.    253   PCjr
  550.    252   PC AT
  551.    251   XT
  552.    250   PS/2 Model 30
  553.    249   PC Convertible
  554.    248   PS/2 Model 70 or 80
  555.    154   Compaq Portable
  556.     45   Compaq Portable
  557.  
  558. Likewise, all but some of the oldest semi-clones maintain a
  559. BIOS date value which tells you how old the BIOS ROM is.  This
  560. can be retrieved with the following routine:
  561.  
  562.    BIOSdate$ = PCDate$
  563.  
  564. If your program is running on one of the rare old machines
  565. which don't maintain a valid BIOS date, this routine will
  566. return "No Date " instead of an actual date.
  567.  
  568. As far as a program is concerned, DR DOS is essentially the
  569. same as MS-DOS.  Still, it's always nice to know what sort of
  570. operating environment you have.  You can find out whether your
  571. program is running under DR DOS with the following function:
  572.  
  573.    IF DRDOS% THEN PRINT "It's DR DOS" ELSE PRINT "MS-DOS"
  574.  
  575. The number of serial and parallel ports available can be
  576. readily obtained:
  577.  
  578.    PRINT "Serial ports: "; CommPorts%
  579.    PRINT "Parallel ports: "; PrtPorts%
  580.  
  581.                          Extended Math                  page 14
  582.  
  583.  
  584.  
  585. The extended math unit provides an expression evaluator and
  586. extensions to BASIC's math.  The math extensions include
  587. hyperbolic and inverse trig functions, a few handy constants,
  588. conversions, and more.  You can use the new math routines by
  589. including these lines at the top of your program:
  590.  
  591.    $LINK "extmatha.obj"
  592.    $LINK "extmathb.pbu"
  593.  
  594. The expression evaluator allows you to find the result of an
  595. expression contained in a string.  Normal algebraic precedence
  596. is used, e.g. 4+3*5 evaluates to 19.  The usual numeric
  597. operators (*, /, +, -, ^) are supported (multiply, divide, add,
  598. subtract, and raise to a power).  Use of negative numbers is
  599. just fine, of course.  Parentheses for overriding the default
  600. order of operations are also supported.
  601.  
  602. You may use either a double asterisk ("**") or a caret ("^")
  603. symbols to indicate exponentiation.
  604.  
  605. The constant PI is recognized, as are the following functions:
  606.    ABS    absolute value        INT    integer
  607.    ACOS   inverse cosine        LOG    natural log
  608.    ASIN   inverse sine          SIN    sine
  609.    ATAN   inverse tangent       SQR    square root
  610.    COS    cosine                TAN    tangent
  611.    FRAC   fraction
  612.  
  613. Trig functions expect angles in radians.
  614.  
  615. To evaluate an expression, you pass it to the evaluator as a
  616. string.  You will get back either an error code or a
  617. single-precision result.  Try this example to see how the
  618. expression evaluator works:
  619.  
  620.    $STACK 8192
  621.    $INCLUDE "pbwiz.inc"
  622.    $LINK "extmatha.obj"
  623.    $LINK "extmathb.pbu"
  624.    DO
  625.       INPUT "Expression? "; Expr$
  626.       IF LEN(Expr$) THEN
  627.          CALL Evaluate (Expr$, Result!, ErrCode%)
  628.          IF ErrCode% THEN
  629.             PRINT "Invalid expression.  Error = "; ErrCode%
  630.          ELSE
  631.             PRINT "Result: "; Result!
  632.          END IF
  633.       END IF
  634.    LOOP WHILE LEN(Expr$)
  635.    END
  636.  
  637. The expression evaluator uses recursion and requires more than
  638. the default amount of stack space, which is why the $STACK
  639. metacommand is used.  See CALC.BAS for a working demo.
  640.  
  641.                          Extended Math                  page 15
  642.  
  643.  
  644.  
  645. The new math functions are pretty much self-explanatory, so
  646. I'll just list them here.  A few general notes are given on the
  647. next page.
  648.  
  649.    Result! = ArcCosHS!(Nr!)       ' inverse hyperbolic cosine
  650.    Result! = ArcSinHS!(Nr!)       ' inverse hyperbolic sine
  651.    Result! = ArcTanHS!(Nr!)       ' inverse hyperbolic tangent
  652.    Result! = ArcCosS!(Nr!)        ' arc cosine  (1 >= Nr >= -1)
  653.    Result! = ArcSinS!(Nr!)        ' arc sine    (1 >= Nr >= -1)
  654.    Result! = ErfS!(Nr!)           ' error function
  655.    Result! = FactS!(Nr%)          ' factorial
  656.    Result! = CotS!(Nr!)           ' cotangent
  657.    Result! = CscS!(Nr!)           ' cosecant
  658.    Result! = SecS!(Nr!)           ' secant
  659.    Result! = CosHS!(Nr!)          ' hyperbolic cosine
  660.    Result! = SinHS!(Nr!)          ' hyperbolic sine
  661.    Result! = TanHS!(Nr!)          ' hyperbolic tangent
  662.    Result! = Deg2RadS!(Nr!)       ' convert degrees to radians
  663.    Result! = Rad2DegS!(Nr!)       ' convert radians to degrees
  664.    Result! = Cent2Fahr!(Nr!)      ' centigrade to Fahrenheit
  665.    Result! = Fahr2Cent!(Nr!)      ' Fahrenheit to centigrade
  666.    Result! = Kg2Pound!(Nr!)       ' convert kilograms to pounds
  667.    Result! = Pound2Kg!(Nr!)       ' convert pounds to kilograms
  668.    Pi! = PiS!                     ' the constant "pi"
  669.    e! = eS!                       ' the constant "e"
  670.    Result! = CeilS!(Nr!)          ' smallest integer >= Nr
  671.    Result! = FloorS!(Nr!)         ' largest integer <= Nr
  672.  
  673.    Result# = ArcCosHD#(Nr#)       ' inverse hyperbolic cosine
  674.    Result# = ArcSinHD#(Nr#)       ' inverse hyperbolic sine
  675.    Result# = ArcTanHD#(Nr#)       ' inverse hyperbolic tangent
  676.    Result# = ArcCosD#(Nr#)        ' arc cosine  (1 >= Nr >= -1)
  677.    Result# = ArcSinD#(Nr#)        ' arc sine    (1 >= Nr >= -1)
  678.    Result# = ErfD#(Nr#)           ' error function
  679.    Result# = FactD#(Nr%)          ' factorial
  680.    Result# = CotD#(Nr#)           ' cotangent
  681.    Result# = CscD#(Nr#)           ' cosecant
  682.    Result# = SecD#(Nr#)           ' secant
  683.    Result# = CosHD#(Nr#)          ' hyperbolic cosine
  684.    Result# = SinHD#(Nr#)          ' hyperbolic sine
  685.    Result# = TanHD#(Nr#)          ' hyperbolic tangent
  686.    Result# = Deg2RadD#(Nr#)       ' convert degrees to radians
  687.    Result# = Rad2DegD#(Nr#)       ' convert radians to degrees
  688.    Pi# = PiD#                     ' the constant "pi"
  689.    e# = eD#                       ' the constant "e"
  690.    Result# = CeilD#(Nr#)          ' smallest integer >= Nr
  691.    Result# = FloorD#(Nr#)         ' largest integer <= Nr
  692.  
  693.                          Extended Math                  page 16
  694.  
  695.  
  696.  
  697.    Result% = GCDI%(Nr1%, Nr2%)    ' greatest common denominator
  698.    Result% = RotateL%(Nr%, Count%) ' rotate left
  699.    Result% = RotateR%(Nr%, Count%) ' rotate right
  700.    Result% = ShiftL%(Nr%, Count%) ' shift left
  701.    Result% = ShiftR%(Nr%, Count%) ' shift right
  702.  
  703.    Result& = GCDL&(Nr1&, Nr2&)    ' greatest common denominator
  704.    Result& = RotateLL&(Nr&, Count%) ' rotate left
  705.    Result& = RotateRL&(Nr&, Count%) ' rotate right
  706.    Result& = ShiftLL&(Nr&, Count%) ' shift left
  707.    Result& = ShiftRL&(Nr&, Count%) ' shift right
  708.  
  709. The ceiling and floor functions are generally used in rounding.
  710.  
  711. Like BASIC's trig functions, the PBWiz trig functions expect
  712. the angle to be in radians.  Conversion functions are provided
  713. in case you prefer degrees.
  714.  
  715. Note that there is no ArcTanS! or ArcTanD# function for the
  716. simple reason that BASIC supplies an ATN function.
  717.  
  718. Constants are expressed to the maximum precision available.
  719.  
  720. If you are not familiar with variable postfix symbols, here's a
  721. brief summary:
  722.  
  723.    Symbol   Meaning             Range (approximate)
  724.    ------   --------            -------------------------------
  725.      %      integer             +- 32767
  726.      &      long integer        +- 2 * 10^9
  727.      !      single precision    +- 1 * 10^38
  728.      #      double precision    +- 1 * 10^308
  729.  
  730. See PowerBASIC's online help for further details.
  731.  
  732.                        Graphics Support                 page 17
  733.  
  734.  
  735.  
  736. I was rather surprised to find that PowerBASIC lacks support
  737. for one of the standard VGA modes-- SCREEN 13, the 320x200
  738. 256-color mode.  I immediately decided to add support for that
  739. mode: dots, lines, boxes, polygons, and (of course) text.
  740. While I was at it, I thought I'd add support for a nonstandard
  741. VGA mode: 360x480 in 256 colors.  This mode will work on almost
  742. any plain VGA system, although it might not work on some older
  743. not-quite-compatible setups.  SuperVGA modes are also supported
  744. for adapters based on the popular Tseng 4000 chip set.
  745.  
  746.    13    320x200, 256 colors, 40x25 text, any VGA
  747.    N0    360x480, 256 colors, 45x60 text, almost any VGA
  748.    N5     ? x ? , 256 colors, ? x ? text, Tseng 4000 SVGA
  749.  
  750. The graphics routines all use the same nomenclature: a G,
  751. followed by a mode number, followed by the specific name.  This
  752. generic naming convention is used so that this chapter can
  753. refer to all available modes.  For example, if I say "G#Color"
  754. and you're using mode 13, you'd actually use "G13Color" in your
  755. program.  Ok?
  756.  
  757. There are two sets of routines for each mode-- the ones written
  758. in ASM and the ones written in BASIC.  The file names for these
  759. will be suffixed with "A" for ASM and "B" for BASIC.  For
  760. instance, to use the SCREEN 13 routines, you would add the
  761. following at the top of your program:
  762.  
  763.    $LINK "g13a.obj"
  764.    $LINK "g13b.pbu"
  765.  
  766. The first thing you will always have to do is to put the screen
  767. into the proper mode.  This is done with the G#Mode routine:
  768.  
  769.    CALL G#Mode (Graphics%)
  770.  
  771. Use 0 to switch to text mode or any other value to switch to
  772. graphics mode.
  773.  
  774. In the case of the N5 routines, you need to initialize the mode
  775. information before your first call to GN5Mode.  That's done by
  776. specifying the BIOS mode number and the screen resolution:
  777.  
  778.    CALL GN5Init (BIOSMode%, PixelsWide%, PixelsHigh%)
  779.  
  780. The BIOS mode, width, height, and amount of video memory
  781. required to support the mode may be any of the following:
  782.  
  783.       &H2D     640 x 350    256k
  784.       &H2E     640 x 480    512k
  785.       &H2F     640 x 400    256k
  786.       &H30     800 x 600    512k
  787.       &H38    1024 x 768     1M
  788.  
  789.                        Graphics Support                 page 18
  790.  
  791.  
  792.  
  793. One difference between BASIC and BasWiz is that, instead of
  794. each "draw" command requiring a color parameter as in BASIC,
  795. the PBWiz library provides a separate color command:
  796.  
  797.    CALL G#Color (Foreground%, Background%)
  798.  
  799. The "foreground" color is used by all graphics routines.  The
  800. background color is used by the G#Cls routine.  Both foreground
  801. and background colors are used in by G#Write and G#WriteLn.
  802.  
  803. Here is a list of the corresponding routines, first BASIC, then
  804. PBWiz (replace the "#" with the appropriate mode number):
  805.  
  806.    ' get the color of a specified point
  807.    colour% = POINT(x%, y%)
  808.    colour% = G#GetPel%(x%, y%)
  809.  
  810.    ' set the color of a specified point
  811.    PSET (x%, y%), colour%
  812.    CALL G#Color (colour%, backgnd%): CALL G#Plot (x%, y%)
  813.  
  814.    ' draw a line of a specified color
  815.    LINE (x1%, y1%) - (x2%, y2%), colour%
  816.    CALL G#Color (colour%, backgnd%)
  817.    CALL G#Line (x1%, y1%, x2%, y2%)
  818.  
  819.    ' draw a box frame of a specified color
  820.    LINE (x1%, y1%) - (x2%, y2%), colour%, B
  821.    CALL G#Color (colour%, backgnd%)
  822.    CALL G#Box (x1%, y1%, x2%, y2%, 0)
  823.  
  824.    ' draw a box of a specified color and fill it in
  825.    LINE (x1%, y1%) - (x2%, y2%), colour%, BF
  826.    CALL G#Color (colour%, backgnd%)
  827.    CALL G#Box (x1%, y1%, x2%, y2%, 1)
  828.  
  829.    ' clear the screen and home the cursor
  830.    CLS
  831.    CALL G#Cls
  832.  
  833.    ' get the current cursor position
  834.    Row% = CSRLIN: Column% = POS(0)
  835.    CALL G#GetLocate (Row%, Column%)
  836.  
  837.    ' set the current cursor position
  838.    LOCATE Row%, Column%
  839.    CALL G#Locate (Row%, Column%)
  840.  
  841.    ' display a string without a carriage return and linefeed
  842.    PRINT St$;
  843.    CALL G#Write (St$)
  844.  
  845.    ' display a string with a carriage return and linefeed
  846.    PRINT St$
  847.    CALL G#WriteLn (St$)
  848.  
  849.                        Graphics Support                 page 19
  850.  
  851.  
  852.  
  853. If you need to print a number rather than a string, just use
  854. the BASIC function STR$ to convert it.  If you don't want a
  855. leading space, use this approach:
  856.  
  857.    St$ = LTRIM$(STR$(Number))
  858.  
  859. The PBWiz library has other routines which have no BASIC
  860. equivalent.  One allows you to get the current colors:
  861.  
  862.    CALL G#GetColor (Foreground%, Background%)
  863.  
  864. Circles and ellipses can be drawn with the Ellipse routine.
  865. This is similar to the BASIC CIRCLE statement.  You specify the
  866. center of the ellipse (X,Y), plus the X and Y radius values:
  867.  
  868.    CALL G#Ellipse (CenterX%, CenterY%, XRadius%, YRadius%)
  869.  
  870. A circle is an ellipse with a constant radius.  So, to draw a
  871. circle, just set both radius values to the same value.
  872.  
  873. As well as the usual points, lines, and ellipses, PBWiz also
  874. allows you to draw regular polygons: triangles, squares,
  875. pentagons, hexagons, and so on.
  876.  
  877.    CALL G#Polygon (X%, Y%, Radius%, Vertices%, Angle!)
  878.  
  879. The X% and Y% values represent the coordinates of the center of
  880. the polygon. The Radius% is the radius of the polygon (as if
  881. you were fitting it into a circle).  Vertices% is the number of
  882. angles (also the number of sides) for the polygon to have.
  883. Angle! specifies the rotation of the polygon, and is specified
  884. in radians.
  885.  
  886.                        Keyboard Control                 page 20
  887.  
  888.  
  889.  
  890. The keyboard is not a particularly exciting or glamorous
  891. device.  In fact, we tend to forget about it except when it
  892. gets in the way.  Sometimes it's a hardware problem-- squishy
  893. or clacking keys, or perhaps a commonly-used key placed in an
  894. out-of-the-way location.  Then again, sometimes it's the
  895. software that's the problem.  There are many aspects of
  896. keyboard control, not all of which are necessarily related to
  897. input.  This unit will let you handle the keyboard in ways you
  898. may not have realized were possible.  Better yet, it can help
  899. make keyboard control easier than the users of your programs
  900. dreamed possible.  It all starts with the one little line:
  901.  
  902.    $LINK "keyboard.obj"
  903.  
  904. Let's start out with keyboard output.  Yep, not input--
  905. output.  We can stuff up to 15 keys into the keyboard buffer.
  906. Why would we ever want to do this? Perhaps to allow your
  907. program to pop-up a TSR automatically, to start another program
  908. after your program ends, or for creating key macros.  You can
  909. enter extended key codes (such as function keys) by using
  910. CHR$(0) before the scan code.
  911.  
  912.    CALL TypeIn (St$)
  913.  
  914. The usual keyboard action is somewhat sluggish.  We can make it
  915. a lot crisper by changing the key repeat rate and the delay
  916. before repeating begins.  This will work on ATs, but not PC/XT
  917. systems.
  918.  
  919.    CALL SpeedKey (RepDelay%, RepRate%)
  920.  
  921. The delay may be 0-3 (1 by default):
  922.  
  923.    0      250 milliseconds
  924.    1      500 milliseconds
  925.    2      750 milliseconds
  926.    3        1 second
  927.  
  928. The repeat rate may be 0-31 (11 by default).  The larger the
  929. number, the slower the speed-- 0 is around 30 cps, and 31 is
  930. around 2 cps.
  931.  
  932. I generally prefer to have the keyboard cranked up to full
  933. speed, using RepDelay% and RepRate% both set to zero.  This may
  934. be a bit too zippy for some people.  Experiment with it to see
  935. what you like best.
  936.  
  937. Of course, there may be reasons to make keyboard repeat less
  938. sensitive instead!  That might be a good idea in programs
  939. written for small children, for example.  You can adjust the
  940. keyboard equally well in either direction.
  941.  
  942.                        Keyboard Control                 page 21
  943.  
  944.  
  945.  
  946. PowerBASIC allows you to control one of the keys which can
  947. interrupt your program, namely the Break key.  There's another
  948. dangerous key which PBWiz allows you to control-- the PrtSc
  949. (PrintScreen) key.  PrtSc may not seem like a hazard at first
  950. glance, but if it's pressed by accident with no printer ready,
  951. or in a graphics mode which PrtSc doesn't understand how to
  952. print, the results can be pretty messy.  So, we let you turn it
  953. off or back on:
  954.  
  955.    CALL SetPrtSc (PrtScON%)
  956.  
  957. Use 0 to turn it off or anything else to turn it back on.  If
  958. you turn off PrtSc, you MUST remember to turn it back on again
  959. before your program ends! Otherwise, an interrupt vector will
  960. point into nowhere, causing probable chaos the next time PrtSc
  961. is pressed.
  962.  
  963. Regardless of whether you've turned the PrtSc key off, you can
  964. print the screen yourself just as if PrtSc had been pressed:
  965.  
  966.    CALL PrintScreen
  967.  
  968. Now here's a strange one for you.  When IBM brought out the
  969. 101-key keyboard, called the "enhanced" keyboard, they did
  970. something bizarre to the BIOS.  They still allowed old keyboard
  971. calls to work, but they filtered out the new key codes so no
  972. one would see them.  This made sure that no one would be able
  973. to use the capabilities of the "enhanced" keyboard without
  974. rewriting their programs.  So, the keyboard has been around for
  975. years, and there are still few programs that even notice when
  976. you press F11.  PowerBASIC v2.1 does not support the enhanced
  977. keyboard at all.  Fortunately, PBWiz -does-.  You can find out
  978. if an enhanced keyboard is installed with the KbdType%
  979. function, which is in the Equipment unit.
  980.  
  981. If there is an enhanced keyboard installed, you can activate it
  982. like so:
  983.  
  984.    CALL SetEnhKbd (Enhanced%)
  985.  
  986. With enhanced keyboard support activated, all key requests that
  987. used the old services are translated to the new services.  So,
  988. SetEnhKbd affects INKEY$ and other BASIC functions as well as
  989. other PBWiz keyboard routines.  Note that you MUST deactivate
  990. enhanced keyboard support before ending your program.
  991. Otherwise, an interrupt vector will point into nowhere,
  992. probably causing a crash on the next keypress!
  993.  
  994.                        Keyboard Control                 page 22
  995.  
  996.  
  997.  
  998. Speaking of INKEY$, I have a neat little function for you.  It
  999. works like INKEY$, but it doesn't remove the key from the
  1000. keyboard buffer:
  1001.  
  1002.    ky$ = ScanKey$
  1003.  
  1004. How is this handy?  Well, let's suppose you're writing
  1005. something that will work like the DIR or TYPE commands in DOS.
  1006. It will display what may be a long listing, which you'd like to
  1007. be able to pause with Ctrl-S or cancel with Ctrl-C.  Trouble
  1008. is, if you use INKEY$ and the user was using "type ahead" to
  1009. store another command, you've just wiped out his command while
  1010. looking for those control codes.  With ScanKey$, you can check
  1011. the key nondestructively.
  1012.  
  1013. On the other hand, if you're about to request important input,
  1014. you may not want to chance having it answered from results of
  1015. the keyboard buffer-- could be that the user meant those keys
  1016. for another purpose.  In that case, it's a good approach to
  1017. clear out the keyboard buffer just before the input:
  1018.  
  1019.    CALL ClearKbd
  1020.  
  1021. No keyboard unit would be complete without a selection of
  1022. routines to check the shift states and get or set the keyboard
  1023. toggles.  Let's start with the toggles, which are so called
  1024. because they get toggled from one state to another:
  1025.  
  1026.     PRINT "Caps Lock  : ";
  1027.     IF CapsOn% THEN PRINT "ON" ELSE PRINT "OFF"
  1028.     PRINT "Insert     : ";
  1029.     IF InsertOn% THEN PRINT "ON" ELSE PRINT "OFF"
  1030.     PRINT "Num Lock   : ";
  1031.     IF NumOn% THEN PRINT "ON" ELSE PRINT "OFF"
  1032.     PRINT "Scroll Lock: ";
  1033.     IF ScrollOn% THEN PRINT "ON" ELSE PRINT "OFF"
  1034.  
  1035. You can also turn the toggles off or on.  It's courteous to
  1036. restore the original toggle states once you end your program,
  1037. so you might want to save the original values for that
  1038. purpose.  Then again, I guess that doesn't apply if your
  1039. program is designed for the specific purpose of setting the
  1040. toggles!
  1041.  
  1042.    CALL SetCaps (CapsLock%)
  1043.    CALL SetInsert (InsertKey%)
  1044.    CALL SetNum (NumLock%)
  1045.    CALL SetScroll (ScrollLock%)
  1046.  
  1047. Does anyone actually use ScrollLock for anything?  Just
  1048. wondering...
  1049.  
  1050.                        Keyboard Control                 page 23
  1051.  
  1052.  
  1053.  
  1054. The shift keys are unique in many respects.  They don't return
  1055. codes that can be detected with INKEY$ or stuffed into the
  1056. keyboard buffer; several can be pressed at the same time; and
  1057. they don't repeat.  You can detect 'em with PBWiz, at any rate:
  1058.  
  1059.    IF AltPress% THEN PRINT "An ALT key is pressed."
  1060.    IF CtrlPress% THEN PRINT "A CTRL key is pressed."
  1061.    IF ShiftPress% THEN PRINT "A SHIFT key is pressed."
  1062.  
  1063.    IF LAltPress% THEN PRINT "The LEFT ALT key is pressed."
  1064.    IF LCtrlPress% THEN PRINT "The LEFT CTRL key is pressed."
  1065.    IF LShiftPress% THEN PRINT "The LEFT SHIFT key is pressed."
  1066.  
  1067.    IF RAltPress% THEN PRINT "The RIGHT ALT key is pressed."
  1068.    IF RCtrlPress% THEN PRINT "The RIGHT CTRL key is pressed."
  1069.    IF RShiftPress% THEN PRINT "The RIGHT SHIFT key is pressed."
  1070.  
  1071. NOTE that LAltPress%, LCtrlPress%, RAltPress%, and RCtrlPress%
  1072. are ONLY available for enhanced keyboards.  They will not
  1073. return useful results on older keyboards.
  1074.  
  1075.                          Memory (EMS)                   page 24
  1076.  
  1077.  
  1078.  
  1079. This unit provides support for expanded memory.  It will work
  1080. with older EMS and EEMS drivers as well as the current EMS 4.0
  1081. standard, with the exception of one or two routines (as noted)
  1082. which take advantage of new capabilities.
  1083.  
  1084. Expanded memory may be present on any type of computer, from
  1085. 8088 PCs to 80486 ATs.  It usually comes as a hardware board
  1086. with a software driver for older machines; on ATs, it may be
  1087. implemented using only a software driver which converts it from
  1088. extended memory.  Drivers have also been written which make a
  1089. hard disk function as EMS memory.  This broad range of use
  1090. makes EMS support invaluable to programs which need extra
  1091. memory.  EMS can theoretically support up to 1 gigabyte of RAM,
  1092. although the documented limit as of v4.0 was only 32 megabytes.
  1093.  
  1094. This unit is called EMS.  You can access it by including this
  1095. line at the top of your program:
  1096.  
  1097.    $LINK "ems.obj"
  1098.  
  1099. Of course, the first thing you need to know is whether any EMS
  1100. memory actually exists:
  1101.  
  1102.    IF EMSexists% THEN PRINT "EMS exists"
  1103.  
  1104. The EMS version may also be retrieved:
  1105.  
  1106.    CALL EMSver (MajorV%, MinorV%)
  1107.  
  1108. It would be a good idea to check the EMS version if you plan to
  1109. use any features which are only available as of EMS 4.0, such
  1110. as reallocation.
  1111.  
  1112. Besides a mere existence and version checks, you will want to
  1113. know how much EMS is available:
  1114.  
  1115.    PRINT "Total EMS installed: "; EMStotal%
  1116.    PRINT "Free EMS memory    : "; EMSfree%
  1117.  
  1118. If you actually tried the above two lines, you would get a pair
  1119. of values which don't seem to mean much.  The trick is to
  1120. multiply them by 16,384 to convert them to bytes.  This is
  1121. because EMS memory is always accessed in pages of 16k bytes
  1122. each.  Any time you are dealing with a quantity of EMS memory,
  1123. the quantity will be specified as a number of pages.
  1124.  
  1125.                          Memory (EMS)                   page 25
  1126.  
  1127.  
  1128.  
  1129. Before we get into the mechanics of accessing EMS memory, I'd
  1130. like to bring up an optional routine which can improve access
  1131. speed.  It should not be used if your program accesses EMS
  1132. using routines other than the ones included here in PBWiz.  If
  1133. you only use these EMS routines, though, you will find that it
  1134. makes some kinds of memory accesses faster.  Use 0 for normal
  1135. (slow) mode.  Do not use optimization if you are using more
  1136. than one EMS handle!
  1137.  
  1138.    CALL EMSopt (Fast%)
  1139.  
  1140. Ok, let's get down to the nitty gritty.  (Where did that
  1141. expression come from, anyway?!)  When you allocate EMS memory,
  1142. you specify the number of pages you want, which must be at
  1143. least 1.  If the allocation is successful, you are returned a
  1144. "handle" which you can use to access the allocated memory.
  1145. Otherwise, you get back an error code.
  1146.  
  1147.    CALL EMSopen (Pages%, Handle%, ErrCode%)
  1148.  
  1149. There are a limited number of handles available under some EMS
  1150. drivers.  The EMS spec, as of v4.0, allowed for a maximum of
  1151. 255 handles, and it's not unusual for a driver to support only
  1152. 20 or so.  Bearing in mind that some of these handles may be
  1153. used up by other applications, such as RAMdisks and caches,
  1154. this really doesn't allow much leeway.  Try to use as few
  1155. handles as possible!  You may well need to store multiple
  1156. values in different areas of the memory allocated for a single
  1157. handle, rather than allocating a new area of memory for each
  1158. value.
  1159.  
  1160. Suppose you find you need more memory than you first
  1161. allocated?  Or maybe less memory?  Well, provided EMS 4.0 or
  1162. later is in use, you can reallocate the block:
  1163.  
  1164.    CALL EMSresize (Handle%, Pages%, ErrCode%)
  1165.  
  1166. There is no way to reallocate memory under older versions of
  1167. EMS.  About the best you could do in that case would be to
  1168. allocate a new area of the desired size, copy over the relevant
  1169. data from the old area, and then deallocate the original area.
  1170. Of course, this assumes that there is enough memory available
  1171. to hold both areas, at least temporarily.
  1172.  
  1173. When you are finished using EMS, you must be sure to return the
  1174. memory you allocated to the system.  It is IMPORTANT to do this
  1175. before ending your program.  Otherwise, the memory you
  1176. allocated will be "lost" until the next time you boot the
  1177. computer.  Return the memory for each handle as follows:
  1178.  
  1179.    CALL EMSclose (Handle%)
  1180.  
  1181.                          Memory (EMS)                   page 26
  1182.  
  1183.  
  1184.  
  1185. Hmmmm... we've covered EMS detection, status info, allocating
  1186. memory, freeing memory, resizing memory... what's missing
  1187. here?  Ah!  We haven't discussed how to actually access the
  1188. memory!
  1189.  
  1190. Accessing EMS memory is quite simple, but it involves a couple
  1191. of steps.  EMS is mapped into a 64k block in the low area of
  1192. memory (the area under 1M, which can be directly accessed).
  1193. Since a page is 16k, the EMS block can hold up to four pages at
  1194. a time.  To transfer data between normal memory and EMS memory,
  1195. you must map the appropriate page(s) of EMS into the EMS
  1196. block.  This is done like so:
  1197.  
  1198.     CALL EMSmap (Handle%, PPage%, VPage%)
  1199.  
  1200. The PPage% is the physical page, that is, the page number
  1201. within the EMS block (0-3).  The VPage% is the virtual page,
  1202. which is the number of a page within the EMS memory associated
  1203. with Handle%.
  1204.  
  1205. Once you've mapped the desired virtual page into a physical
  1206. page, it can be accessed using standard PowerBASIC memory
  1207. commands, such PEEK$ and POKE$. First, set the segment:
  1208.  
  1209.    DEF SEG=EMSseg&
  1210.  
  1211. The offset within a page may be 0-16,383.  To get the
  1212. appropriate offset within the EMS block, you must add the
  1213. offset of the page itself.  This may be calculated as follows:
  1214.  
  1215.    DataOffset& = OffsetWithinPage% + PageNumber% * 16384&
  1216.  
  1217. One final note: for best compatibility, it would be good to
  1218. avoid using physical page 3 (the last 16k of the EMS block).
  1219. Some EMS drivers don't handle this page with complete accuracy,
  1220. for technical reasons I'm not going to get into right now.
  1221.  
  1222.                          Memory (XMS)                   page 27
  1223.  
  1224.  
  1225.  
  1226. This unit provides support for XMS extended memory.  It won't
  1227. work with extended memory unless an XMS driver is present.
  1228.  
  1229. Extended memory is only present in AT-class computers.  It is
  1230. not available on older PCs.  An XMS driver must also be used.
  1231. XMS drivers are included with MS-DOS 5.0 and Windows 3.0, among
  1232. other things, so this is not a major limitation.  XMS can
  1233. address a maximum of 64 megabytes.
  1234.  
  1235. This unit is called XMS.  You access it by including this line
  1236. at the top of your program:
  1237.  
  1238.    $LINK "xms.obj"
  1239.  
  1240. The first thing to check is whether any XMS memory exists:
  1241.  
  1242.    IF XMSexists% THEN PRINT "XMS exists"
  1243.  
  1244. The XMS version may also be retrieved:
  1245.  
  1246.    CALL XMSver (MajorV%, MinorV%)
  1247.  
  1248. The amount of XMS memory available may be reported in either of
  1249. two different ways: total amount and largest available block.
  1250.  
  1251.    PRINT "Total XMS free    : "; XMStfree&
  1252.    PRINT "Largest free block: "; XMSlfree&
  1253.  
  1254. XMS memory is manipulated in terms of 1,024 byte blocks, so the
  1255. amount of free memory is reported in kilobytes.  Any time you
  1256. are dealing with a quantity of EMS memory, the quantity will be
  1257. specified as a number of 1K blocks, except as otherwise noted.
  1258.  
  1259.                          Memory (XMS)                   page 28
  1260.  
  1261.  
  1262.  
  1263. When you allocate XMS memory, you specify the number of
  1264. kilobytes that you want.  This may be 0-65535, in theory.
  1265. Dunno, I don't have 64M RAM <grin>. If the allocation is
  1266. successful, you are returned a "handle" which you can use to
  1267. access the allocated memory.  Otherwise, you get back an error
  1268. code.
  1269.  
  1270.    CALL XMSopen (KBytes&, Handle%, ErrCode%)
  1271.  
  1272. There are a limited number of handles available, although the
  1273. number can be controlled somewhat by a driver parameter.  It's
  1274. probably best to use as few handles as possible, to avoid
  1275. running out.  You may well want to store multiple values in
  1276. different areas of the memory allocated for a single handle,
  1277. rather than allocating a new area of memory for each value.
  1278.  
  1279. Suppose you find you need more memory than you first
  1280. allocated?  Or maybe less memory?  Just reallocate the block:
  1281.  
  1282.    CALL XMSresize (Handle%, KBytes&, ErrCode%)
  1283.  
  1284. When you are finished using XMS, you must be sure to return the
  1285. memory you allocated to the system.  It is IMPORTANT to do this
  1286. before ending your program.  Otherwise, the memory you
  1287. allocated will be "lost" until the next time you boot the
  1288. computer.  Return the memory for each handle as follows:
  1289.  
  1290.    CALL XMSclose (Handle%)
  1291.  
  1292. To transfer data between normal memory and XMS memory, you must
  1293. provide the segment and offset of the normal memory area (use
  1294. the PowerBASIC functions VARSEG and VARPTR to find the address
  1295. of a variable).  The position within XMS memory is specified as
  1296. a long-integer offset starting at zero.
  1297.  
  1298.     CALL XMSread (Handle%, Posn&, Bytes&, DSeg%, DOfs%)
  1299.  
  1300.     CALL XMSwrite (Handle%, Posn&, Bytes&, DSeg%, DOfs%)
  1301.  
  1302. Note that the Bytes& to transfer must be an EVEN NUMBER.  It is
  1303. not restricted to 64k, however, so you can transfer a great
  1304. deal of data with these routines.
  1305.  
  1306. The XMS spec guarantees a "reasonable" number of interrupt
  1307. windows during a transfer; however, it is possible that you
  1308. might experience some communications dropouts if you do large
  1309. transfers during high-speed telecommunications.  If this is
  1310. expected to happen, test it carefully.
  1311.  
  1312.                          Mouse Support                  page 29
  1313.  
  1314.  
  1315.  
  1316. The mouse unit provides full-featured mouse support.  You can
  1317. see if a mouse is available and how many buttons it has, get
  1318. the cursor position (either the current position or the
  1319. position at the last press or release of a specified button),
  1320. set the cursor position, change the cursor, set the mouse
  1321. range, get hardware information about the mouse, and so on.
  1322.  
  1323. This unit is called MOUSE, so you access it by including the
  1324. following line at the top of your program:
  1325.  
  1326.    $LINK "mouse.obj"
  1327.  
  1328. There are two unusual mouse modes to be aware of.  One is text
  1329. mode, which is mapped to a 640x200 virtual display.  So, to
  1330. convert the results to text format, you need to divide the
  1331. cursor position by eight and add one.  To convert from text
  1332. format, subtract one and multiply by eight.
  1333.  
  1334. The second unusual mode is 320x200 CGA mode, which is also
  1335. mapped to 640x200. To convert the coordinates to this mode,
  1336. divide X by two.  To convert from this mode, multiply the X
  1337. coordinate by two.
  1338.  
  1339. All other modes use the actual display coordinates instead of a
  1340. bizarro virtual screen.  Why the peculiar CGA and text modes?
  1341. Well, evidently Microsoft never thought there'd be any video
  1342. adapters besides MDA and CGA, and decided to create a single
  1343. virtual screen size that worked for all modes. Not a bad idea,
  1344. I guess, but rather shortsighted.  Oh well.
  1345.  
  1346. One other nuisance that you may run into is that the mouse
  1347. cursor can't be directly turned on or off.  A "cursor
  1348. visibility" count is maintained-- if the mouse cursor was
  1349. turned on twice, you'll need to turn it off twice before it
  1350. will actually disappear.
  1351.  
  1352. Before using the mouse, you must initialize it.  The
  1353. initialization routine also checks to make sure that a mouse is
  1354. installed and tells you how many buttons it has.  It's best to
  1355. initialize the mouse after setting the screen mode, so the
  1356. mouse driver understands what mode you're using.  Not all mouse
  1357. drivers support all screen modes, but you can reasonably expect
  1358. any current mouse driver to support MDA, CGA, EGA, and VGA.
  1359. Hercules graphics mode is rarely supported, as it must be set
  1360. through direct hardware access rather than the standard
  1361. techniques, so the mouse driver has little way of knowing that
  1362. you've changed the mode.
  1363.  
  1364. The mouse routines will work equally well with two-button or
  1365. three-button rodents.  The middle button functions will return
  1366. 0 with two-button mice.
  1367.  
  1368.                          Mouse Support                  page 30
  1369.  
  1370.  
  1371.  
  1372. I won't go into great detail on these routines, because they're
  1373. pretty much self-explanatory.  The mouse is a fairly easy
  1374. device to deal with.
  1375.  
  1376. You can initialize the mouse driver like so:
  1377.  
  1378.    Buttons% = MouseInit%
  1379.  
  1380. This returns the number of mouse buttons available.  If there
  1381. is no mouse, zero will be returned.  Initialize the mouse after
  1382. setting the screen mode.
  1383.  
  1384. You can make the mouse cursor visible or invisible.  It will
  1385. function just as well in either state.  See the previous page
  1386. for some quirks.
  1387.  
  1388.    CALL MouseShow       ' show the cursor
  1389.    CALL MouseHide       ' hide the cursor
  1390.  
  1391. There are many ways to get the mouse cursor position.  You can
  1392. get the current position, the position at which the mouse was
  1393. located when a particular button was pressed, or the position
  1394. when a button was released. If you choose a past position, you
  1395. can also find out how many presses or releases of the button
  1396. have taken place since you last checked.
  1397.  
  1398.    X% = MouseWhereX%                   ' current X coordinate
  1399.    Y% = MouseWhereY%                   ' current Y coordinate
  1400.  
  1401.    CALL MouseLClick (Count%, X%, Y%)   ' left presses & posn
  1402.    CALL MouseMClick (Count%, X%, Y%)   ' middle presses & posn
  1403.    CALL MouseRClick (Count%, X%, Y%)   ' right presses & posn
  1404.  
  1405.    CALL MouseLRelease (Count%, X%, Y%) ' left releases & posn
  1406.    CALL MouseMRelease (Count%, X%, Y%) ' middle releases & posn
  1407.    CALL MouseRRelease (Count%, X%, Y%) ' right releases & posn
  1408.  
  1409. If you'd prefer to find out which buttons are currently
  1410. pressed, no problem:
  1411.  
  1412.    Pressed% = MouseLButton%  ' whether left button is pressed
  1413.    Pressed% = MouseMButton%  ' whether middle button is pressed
  1414.    Pressed% = MouseRButton%  ' whether right button is pressed
  1415.  
  1416. Of course, you can also set the cursor location:
  1417.  
  1418.    CALL MouseLocate (X%, Y%)   ' set the mouse cursor position
  1419.  
  1420. The mouse cursor range can be restricted to a given area of the
  1421. screen.  This area is expressed by giving the upper left corner
  1422. and lower right corner of the rectangular area to which to
  1423. restrict the cursor.
  1424.  
  1425.    CALL MouseWindow (X1%, Y1%, X2%, Y2%)
  1426.  
  1427.                          Mouse Support                  page 31
  1428.  
  1429.  
  1430.  
  1431. There are a variety of cursor shapes available for graphics
  1432. mode:
  1433.  
  1434.     0    hourglass ("please wait, program is working" symbol)
  1435.     1    pointing arrow (default)
  1436.     2    pointing hand
  1437.     3    crosshair
  1438.     4    target (box in a box)
  1439.     5    grabbing hand
  1440.  
  1441. If you have ideas for more, let me know and I'll see what I can
  1442. do.  Cursor shapes are not unduly difficult to define.
  1443.  
  1444. The cursor image is set like so:
  1445.  
  1446.    CALL MouseCursorG (CursorNr%)
  1447.  
  1448.                             Strings                     page 32
  1449.  
  1450.  
  1451.  
  1452. One of the true strengths of BASIC lies in its powerful string
  1453. handling capability.  I'd be remiss if I didn't provide
  1454. extensions which improve it even further.  This unit can be
  1455. accessed by including this line at the top of your program:
  1456.  
  1457.    $LINK "stringa.obj"
  1458.    $LINK "stringb.pbu"
  1459.  
  1460. The simplest of the PBWiz string routines may seem somewhat
  1461. whimsical, but it has proven useful to me on several occasions
  1462. in the past.  It reverses the order of characters in a string.
  1463.  
  1464.    CALL Reverse (St$)
  1465.  
  1466. One of the places this has come in useful is in searching a
  1467. string from the end-- a reverse INSTR routine:
  1468.  
  1469.    CALL RInstr (MainSt$, SubSt$, Posn%)
  1470.  
  1471. Rather than returning the first occurrence of a substring
  1472. within a main string, it returns the last occurrence.  Another
  1473. handy string search allows you to search for various types of
  1474. characters, rather than a specific substring:
  1475.  
  1476.    CALL TInstr (MainSt$, Types%, Posn%)
  1477.  
  1478. The type(s) may be specified using any combination of the
  1479. following.  Just add them together.
  1480.  
  1481.     1    alphabetic
  1482.     2    numeric
  1483.     4    symbolic
  1484.     8    control
  1485.    16    graphics
  1486.    32    space
  1487.  
  1488. Since you can search for any specific types, you can also
  1489. readily invert the search to look for any characters that are
  1490. NOT of a given type or types:
  1491.  
  1492.    Types% = NOT Types%
  1493.  
  1494. This gives you complete control.  A typical use for TInstr
  1495. might be to clean up user input and make sure that it's valid.
  1496. It's also good for parsing.
  1497.  
  1498.                             Strings                     page 33
  1499.  
  1500.  
  1501.  
  1502. Another routine that is useful for cleaning up and parsing user
  1503. input is called Crunch.  It allows you to eliminate adjacent
  1504. duplicates of a character or list of characters.  One use for
  1505. this, for instance, would be to eliminate repeated spaces,
  1506. converting an input string from "*.*    *.BAK  /B" to a more
  1507. manageable "*.* *.BAK /B".
  1508.  
  1509.    Result$ = Crunch$(St$, CharList$)
  1510.  
  1511. There are a pair of routines that you'll find valuable if you
  1512. need to check the validity of a string.  These are designed to
  1513. be compatible with the Xmodem and Ymodem file transfer
  1514. protocols, so you can use them for error checking in
  1515. telecommunications as well.
  1516.  
  1517.    Chk% = CheckSum% (St$)
  1518.  
  1519.    CALL CRC16 (St$, HiCRC%, LoCRC%)
  1520.  
  1521. Another pair of string routines provide a simple encryption
  1522. and decryption system for text.  The method used is not
  1523. particularly secure but are very fast and will be adequate for
  1524. many purposes.  As always, it helps to use a long and/or
  1525. complex password.
  1526.  
  1527.    CALL Cipher (St$, Password$)
  1528.    CALL CipherP (St$, Password$)
  1529.  
  1530. Both of these routines will encipher text on the first
  1531. run-through and decipher on the second, so you can use the same
  1532. routine either to encrypt or decrypt a message.  They are
  1533. different in one respect: the encrypted result of Cipher may
  1534. contain control characters, so it can't be used in a plain
  1535. sequential-access file.  The CipherP routine does not allow use
  1536. of extended ASCII characters (CHR$(128) - CHR$(255)), as it
  1537. sets the high bit on each character after encrypting it.  This
  1538. causes the results of CipherP to be printable (and useful in
  1539. sequential-access files), although they will look very strange.
  1540.  
  1541. The strings are encrypted (or decrypted) in place.  This
  1542. provides a certain extra measure of security for encryption--
  1543. the original plaintext strings are not left floating around in
  1544. memory where someone might see them.
  1545.  
  1546. One function is as much a file manipulation routine as it is a
  1547. string function.  It allows you to compare a file name to a
  1548. file pattern (which may contain wildcards) to see if they
  1549. match.  Only bare filespecs are supported-- you may not use
  1550. drive or path specifications in the names.
  1551.  
  1552.    IF MatchFile% (Pattern$, Filename$) THEN PRINT Filename$
  1553.  
  1554.                             Strings                     page 34
  1555.  
  1556.  
  1557.  
  1558. The MatchFile function can be used in creating your own
  1559. DOS-style utilities: DIR, COPY, and so forth.  Besides the
  1560. usual "accept file if it matches" approach, it can also be used
  1561. to implement the opposite: "exclude file if it matches."  This
  1562. gives you more flexibility than DOS itself supplies.
  1563.  
  1564. The PowerBASIC compiler provides a very nice function called
  1565. Extract$.  This allows you to retrieve a substring running from
  1566. the left side of a main string to a specified character
  1567. delimiter.  Not bad, but it might be handy to be able to grab a
  1568. numbered substring from any part of a main string, and to be
  1569. able to use a substring delimiter.  For instance, you might
  1570. load a record from a database which contains an address, where
  1571. each line is delimited by a carriage return and linefeed.
  1572. Rather than mucking around with Extract$, which really wasn't
  1573. designed with that sort of thing in mind, you'd do better to
  1574. use the PBWiz function called DelimExtract$:
  1575.  
  1576.    SubSt$ = DelimExtract$(St$, Delimiter$, Index%)
  1577.  
  1578. The index starts at 1 with the first substring.  If you choose
  1579. the index of a substring which doesn't actually exist, a null
  1580. string will be returned.
  1581.  
  1582.                         Text-mode Video                 page 35
  1583.  
  1584.  
  1585.  
  1586. Routines in this unit may be accessed if you include these
  1587. lines at the top of your program:
  1588.  
  1589.    $LINK "videoa.obj"
  1590.    $LINK "videob.pbu"
  1591.  
  1592. The graphical interface has become a "sexy" thing to have
  1593. these days, but there are still many good reasons to work in
  1594. text mode.  It's relatively fast, it works on all monitors,
  1595. and it's often the most appropriate choice.  Graphics is
  1596. overkill for many applications.  Besides, you can't redirect
  1597. graphics to a file or to the printer.
  1598.  
  1599. Come to think of it, text displayed by the PRINT statement
  1600. can't be redirected either.  Fortunately, we can fix that.
  1601. All it takes is sending the output through DOS:
  1602.  
  1603.    CALL DOSPrint (St$)   ' print to the current output device
  1604.  
  1605. A nice thing about DOS output is that ANSI display codes will
  1606. work if you have an ANSI driver (such as ANSI.SYS) installed.
  1607. If you're working with existing text, such as captured output
  1608. from a BBS or from an ANSI art program like TheDraw, you can
  1609. just use the DOSPrint routine to handle it.  If you're looking
  1610. to do your own ANSI output, though, there's an easier way than
  1611. looking up the individual codes and sending 'em out one at a
  1612. time.  The following routines send the appropriate ANSI codes
  1613. to the current DOS output device:
  1614.  
  1615.    CALL DOSCls                      ' clear the screen
  1616.    CALL DOSColor (Fore%, Back%)     ' set the screen colors
  1617.    CALL DOSLocate (Row%, Column%)   ' set the cursor position
  1618.  
  1619. The primary advantage of DOS output is that it can be
  1620. intercepted.  It normally goes to the screen, but you can
  1621. redirect it to a file, printer, or comm port, among other
  1622. things.  You can also be sure that DOS output will work
  1623. reasonably in a multitasking environment like DESQview or
  1624. Windows, instead of messing up the screen.  The disadvantage
  1625. is that DOS output is fairly slow.  It's great for command
  1626. line utilities, but not if you plan to do any fancy screen
  1627. work.  For that, you probably want direct-access techniques.
  1628.  
  1629. The direct screen access provided by PBWiz is rude, crude...
  1630. and faster than a greased euphemism.  It can't be redirected,
  1631. doesn't handle control codes, and won't even update the cursor
  1632. position.  In return for this lack of amenities, it gives you
  1633. two very valuable things: complete control and raw speed.
  1634.  
  1635.                         Text-mode Video                 page 36
  1636.  
  1637.  
  1638.  
  1639. The direct-access replacement for PRINT works like so:
  1640.  
  1641.    CALL XQPrint (St$, Row%, Column%, Attr%)
  1642.  
  1643. Now, you might guess that St$ is the text to print, and Row%
  1644. and Column% are where to print it.  The Attr% may seem a bit
  1645. more opaque.  The Attr% is the color to use-- actually, both
  1646. the foreground and background colors.  These are combined into
  1647. a single value because that's the way the display controller
  1648. wants to see it.  Remember, the emphasis here is on speed, not
  1649. necessarily convenience!  So how do you calculate an attribute
  1650. given the foreground and background colors?
  1651.  
  1652.    Attr% = CalcAttr% (Fore%, Back%)
  1653.  
  1654. An Attr% value is never less than 0 or greater than 255-- it
  1655. will fit into a single byte.  That may be useful to know for
  1656. storage purposes.  In any event, keep the Attr% in mind,
  1657. because we'll be seeing more of it in the future.  By the way,
  1658. you can unpack an attribute into foreground and background
  1659. colors too, if need be:
  1660.  
  1661.    CALL UnCalcAttr (Attr%, Fore%, Back%)
  1662.  
  1663. In addition to XQPrint, there is a routine which allows you to
  1664. overlay existing text rather than replacing it.  It skips
  1665. blank spaces rather than putting them on the display.
  1666.  
  1667.    CALL XQPrintOver (St$, Row%, Column%, Attr%)
  1668.  
  1669. The direct-access routines allow for one, and only one, option
  1670. which might slow them down.  The IBM CGA and some clone CGAs
  1671. flicker horribly if you access their display memory directly.
  1672. There is a software fix, but it slows the display down
  1673. tremendously.  Still, if your program is run on such a CGA,
  1674. you'll want to stop the flickering.  This may be done so:
  1675.  
  1676.    CALL AntiSnow (Slow%)   ' any nonzero value to stop flicker
  1677.  
  1678. You should provide a command-line switch or configuration
  1679. option to force anti-flicker support.  Don't do it by default,
  1680. as the slowdown is very noticeable.
  1681.  
  1682. The "menu" approach has become the standard way of allowing a
  1683. user to choose between various program options.  There are
  1684. many ways of designing a menu, but they almost always require
  1685. a "highlight" to show the current choice.  This highlight is
  1686. generally handled by changing the color of the chosen item:
  1687.  
  1688.    CALL ReColorArea (TopRow%, LftCol%, BotRow%, RtCol%, Attr%)
  1689.  
  1690.                         Text-mode Video                 page 37
  1691.  
  1692.  
  1693.  
  1694. Pop-up windows have become ubiquitous.  Naturally, PBWiz
  1695. supports them too:
  1696.  
  1697.    CALL PopWindow (TRow%, LCol%, BRow%, RCol%, Frame%,
  1698.       Attr%, Grow%, Shade%, TFore%, Title$)   ' use one line!
  1699.  
  1700. The first four parameters specify the upper left corner and
  1701. lower right corner of the window.  The window frame, if any,
  1702. is created just outside these coordinates.  If you choose a
  1703. shadow for a 3D effect, that will extend further outside the
  1704. window.  Keep this in mind if you want to save the part of the
  1705. screen under the window... but we'll get to that!  Let's see
  1706. what options are available for the frame type:
  1707.     0   no frame
  1708.     1   single lines
  1709.     2   double lines
  1710.     3   single horizontal, double vertical lines
  1711.     4   double horizontal, single vertical lines
  1712.     5   block graphic lines
  1713.  
  1714. These are the available shadows:
  1715.    -3   transparent shadow on the right
  1716.    -2   transparent shadow on the left
  1717.    -1   solid black shadow on the left
  1718.     0   no shadow
  1719.    1+   shadow attribute (use CalcAttr) for a colored shadow
  1720.  
  1721. Options for growing windows are as follows:
  1722.    -1   grow as fast as possible
  1723.     0   pop onto the screen
  1724.    1+   grow with a specified delay in milliseconds
  1725.         (15 works well for me)
  1726.  
  1727. The TFore% parameter is the foreground color to use for the
  1728. title (Title$), if any (use "" for no title).
  1729.  
  1730. It is worth noting that the "milliseconds" value is only
  1731. rather approximate.  The delay is based on the video card, and
  1732. is fairly similar on any computer system, but there will be a
  1733. noticeable difference between (say) an XT with a CGA and a 486
  1734. with a VGA.  Still, it's a useful delay-- if not really
  1735. precise, it's at least fairly accurate, and it has a fine
  1736. resolution.  You can access this delay yourself:
  1737.  
  1738.    CALL DelayV (MilliSeconds%)
  1739.  
  1740.                         Text-mode Video                 page 38
  1741.  
  1742.  
  1743.  
  1744. I mentioned screen saves a bit earlier.  With PBWiz, you can
  1745. save any part of a screen, and restore it later to the same
  1746. place or an entirely different area.  This also offers the
  1747. possibility of creating a screen image, storing it in a file,
  1748. and reading it into your program, among other things.  It
  1749. works like this:
  1750.  
  1751.    Scr$ = ScreenSave$ (TopRow%, LftCol%, BotRow%, RtCol%)
  1752.  
  1753.    CALL ScreenRestore (Scr$, TopRow%, LftCol%)
  1754.  
  1755. It takes about 4K to store a full 80x25 text screen.  The
  1756. exact calculation is Bytes = Rows * Columns * 2 + 2, if you
  1757. care to figure it out yourself. You can also take advantage of
  1758. a PBWiz routine to handle it:
  1759.  
  1760.    Bytes% = CalcSize% (TopRow%, LftCol%, BotRow%, RtCol%) + 2
  1761.  
  1762. Finally, we are left with a series of routines which let you
  1763. scroll (or clear) any part of the screen:
  1764.  
  1765.    CALL ScrollDown (TRow%, LCol%, BRow%, RCol%, Times%, Attr%)
  1766.    CALL ScrollLeft (TRow%, LCol%, BRow%, RCol%, Times%, Attr%)
  1767.    CALL ScrollRight (TRow%, LCol%, BRow%, RCol%, Times%, Attr%)
  1768.    CALL ScrollUp (TRow%, LCol%, BRow%, RCol%, Times%, Attr%)
  1769.  
  1770. If you attempt to scroll zero times, or more times than there
  1771. are rows (or columns, depending on which way you scroll), the
  1772. specified area of the screen will be cleared.  The Attr% gives
  1773. the color to use on the cleared area of the screen.
  1774.  
  1775.                             Credits                     page 39
  1776.  
  1777.  
  1778.  
  1779. I'd like to thank Dave Navarro for letting me in on the world
  1780. of PowerBASIC. His assistance has been most valuable to me in
  1781. many respects.  Without him, this library would have taken much
  1782. longer to get off the ground or would perhaps not even exist.
  1783.  
  1784. I would also like to thank Spectra, publishers of PowerBASIC,
  1785. for sending me the evaluation copy of PowerBASIC which led to
  1786. my decision to write this library.
  1787.  
  1788.